<?php
class ProductRecommendInfo extends CWidget
{
	public $htmlOptions = array();

	public $length = 30;
	public $id;
	
	public $dataProvider;
	
	public function getData()
	{
		
		$result = array();
		$i = 0;
		
		$product = Product::model()->findAll(array(
			'condition'=>'pro_recommend = :pro_recommend',
			'limit'=>5,
			'order'=>'pro_id DESC',
			'params'=>array(
				':pro_recommend'=>Product::RECOMMEND_ALLOW
			)
		));
		
//		UtilTools::dump($product);
		foreach ($product as $data)
		{
			$i++;
			$result[$i]['category'] = $data->category->cate_name;
			$result[$i]['content'] = UtilTools::strSlice(trim(strip_tags($data->pro_describe)),0,125);
			$result[$i]['link'] = Yii::app()->createUrl('product/details',array('id'=>$data->pro_id));
			$result[$i]['title'] = CHtml::link($data->pro_name,array('product/details','id'=>$data->pro_id));
			$result[$i]['folder'] = CHtml::link(CHtml::image(File::model()->generateFilePath($data->folder,0,1),$data->pro_name),array('product/details','id'=>$data->pro_id));
		}
		
		shuffle($result);
		$this->dataProvider = json_encode($result);
		
	}
	
	
	public function run()
	{	
		$this->getData();
		
		$this->render('site',array(
			'dataProvider' => $this->dataProvider
		));
	}
}